package org.cfk.delaytasktutorial.service.impl;

import lombok.RequiredArgsConstructor;
import org.cfk.delaytasktutorial.entity.LazyJobDeadLetter;
import org.cfk.delaytasktutorial.mapper.LazyJobDeadLetterMapper;
import org.cfk.delaytasktutorial.service.LazyJobDeadLetterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class LazyJobDeadLetterServiceImpl implements LazyJobDeadLetterService {

    private final LazyJobDeadLetterMapper lazyJobDeadLetterMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(String worker, String content, LocalDateTime util) {
        LazyJobDeadLetter deadLetter = new LazyJobDeadLetter()
                .setWorker(worker)
                .setContent(content)
                .setUtil(util)
                .setDeleted(false)
                .setCreateTime(LocalDateTime.now());
        lazyJobDeadLetterMapper.insert(deadLetter);
    }
}